-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[TF-76] file renames + split PythonConvertible protocol #23891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you'll need to rename usages of NumpyConversionTests
to PythonConversionTests
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This file defines conversion logic between Python types & | |
// This file defines conversions between Python types and TensorFlow library | |
// types. |
@dan-zheng My bad, noticed the Python/Numpy test naming right after hitting submit. Should be good now. |
@swift-ci Please test tensorflow |
@swift-ci Please test tensorflow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some important issues I missed in the last merged PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(hasLen == true) { | |
if Python.hasattr(pythonObject, "__len__" == true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End sentences with a period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be 80 columns long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rxwei is there a linter I can install to catch this kind of stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't review the last change closely. Maybe tests broke because TensorShape(0)
's initialization defaulted to TensorShape(0 as PythonObject)
somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rxwei Yep, that is exactly the case. I spent some time looking into how to manipulate the prority order of the initializers, but if you have a suggested approach i can definitely try it out. I settled for just making sure that this initializer successfully passes through to the correct initializer, since TensorShape(0 as PythonObject)
should be valid anyway.
It is also possible that the failure was due to this initializer being failable, but the only reliable repro steps are what I outlined here.
I guess the question is what would you want/expect the output of the below program to be?
func doThing(_ arg: PythonObject) {
print(type(of: arg))
}
func doThing(_ arg: Int32) {
print(type(of: arg))
}
doThing(1)
Output currently is PythonObject. Perhaps that is the real underlying bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. There are two bigger problems. First, the TensorFlow module shouldn't logically depend on Python, i.e. there can be targets that require all APIs that use Python be #if
'd out. Second, we ultimately want to optimize tensor operations through techniques like graph program extraction, but having this Python layer for the initialization of a simple tensor shape makes it extremely inefficient when we are targeting hardware like TPUs.
I think a better solution would be to split this protocol into two. This has actually been on my mind for over a year now:
PythonConvertible
defines conversion to Python; ConvertibleFromPython
defines conversion from Python.
TensorShape
will then only conform to PythonConvertible
, but not the other one, making this integer literal issue go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, makes sense. I could definitely work on a PR for the split up of the protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Let's do that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matching scalar does seem right to me. Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rxwei the reason is that [Int32](1)
(and [Int32](1 as PythonObject)
) is not valid in Swift, but TensorShape(1)
is valid. Or do you mean that you would just prefer [Int32]([pythonObject])
here?
@dan-zheng ok, made the syntax updates here in case you want to merge just this. I'll follow up later this weekend with the protocol split. |
@dan-zheng @rxwei this branch has the protocol split on it now. |
Oh excellent. We can skip the revert then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. Thanks Doug!
Co-Authored-By: realdoug <dfriedm3@gmail.com>
Co-Authored-By: realdoug <dfriedm3@gmail.com>
Co-Authored-By: realdoug <dfriedm3@gmail.com>
@swift-ci please test tensorflow |
3 similar comments
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow Linux |
@swift-ci please test tensorflow |
CI seems dead. This PR needs to go in before #24012. @dan-zheng could you help make sure this gets tested? |
Co-Authored-By: realdoug <dfriedm3@gmail.com>
@swift-ci Please test tensorflow |
1 similar comment
@swift-ci Please test tensorflow |
@swift-ci please test tensorflow |
@swift-ci please test tensorflow, seriously |
@swift-ci Please test tensorflow EDIT: I think Jenkins is busy. https://ci-external.swift.org/computer/ubuntu-16.04-tensorflow |
@swift-ci please test tensorflow |
@swift-ci Please test tensorflow |
@swift-ci Please test tensorflow linux |
@swift-ci please test tensorflow Linux |
There is one test failure:
|
NumPy arrays have tuple shapes, not list shapes.
@swift-ci Please test tensorflow |
ugh sorry bout that! Could have sworn that passed locally for me. |
naming & code organization changes as discussed here